package com.mzba.place.ui;

import android.content.Intent;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.mzba.place.BasicActivity;
import com.mzba.place.R;
/**
 * 筛选
 * @author 06peng
 *
 */
public class FilterReportsActivity extends BasicActivity {
	
	private Spinner reportTypeSpinner;
	private Spinner reportTimeSpinner;
	
	private ArrayAdapter<CharSequence> reportTypeAdapter;
	private ArrayAdapter<CharSequence> reportTimeAdapter;
	
	private final int menu_confirm = 1;

	@Override
	protected void onCreate(Bundle paramBundle) {
		super.onCreate(paramBundle);
		setTheme(R.style.Theme_Sherlock);
		setContentView(R.layout.filter_reports);
		actionBar.show();
		actionBar.setDisplayShowTitleEnabled(true);
		actionBar.setTitle("筛选上报信息");
		setSupportProgressBarIndeterminateVisibility(false);
		
		reportTypeSpinner = (Spinner) findViewById(R.id.report_type_spinner);
		reportTimeSpinner = (Spinner) findViewById(R.id.report_time_spinner);
		
		reportTypeAdapter = ArrayAdapter.createFromResource(this, R.array.reportType, R.layout.spinner_item);
		reportTypeAdapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
		reportTypeSpinner.setAdapter(reportTypeAdapter);
		
		reportTimeAdapter = ArrayAdapter.createFromResource(this, R.array.reportTime, R.layout.spinner_item);
		reportTimeAdapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
		reportTimeSpinner.setAdapter(reportTimeAdapter);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		menu.add(0, menu_confirm, 0, "确定").setIcon(R.drawable.abs__ic_cab_done_holo_dark).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
		return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			finish();
			break;
		case menu_confirm:
			int type = reportTypeSpinner.getSelectedItemPosition();
			int time = reportTimeSpinner.getSelectedItemPosition();
			Intent intent = new Intent(this, MainActivity.class);
			intent.putExtra("report_type", type);
			intent.putExtra("report_time", time);
			setResult(RESULT_OK, intent);
			finish();
			break;
		default:
			break;
		}
		return false;
	}
}
